<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="订单来源名称" prop="orderSourceName">
      <el-input v-model="dataForm.orderSourceName" placeholder="来源名称"></el-input>
    </el-form-item>
<!--    <el-form-item label="系统内置" prop="systemBuiltIn">-->
<!--			<el-radio v-model="dataForm.systemBuiltIn" label="1">是</el-radio>-->
<!--			<el-radio v-model="dataForm.systemBuiltIn" label="2">否</el-radio>-->
<!--    </el-form-item>-->
    <el-form-item label="备注" prop="remark">
      <el-input v-model="dataForm.remark" placeholder="备注"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()" :disabled="disabledSubmit">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
				disabledSubmit:false,
        visible: false,
        dataForm: {
          orderSourceId: 0,
          orderSourceName: '',
          systemBuiltIn: '',
          remark: ''
        },
        dataRule: {
          orderSourceName: [
            { required: true, message: '来源名称不能为空', trigger: 'blur' }
          ],
          systemBuiltIn: [
            { required: true, message: '是否系统内置(1是2否)不能为空', trigger: 'blur' }
          ],

        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.orderSourceId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.orderSourceId) {
            this.$http({
              url: this.$http.adornUrl(`/store/tstoreordersource/info/${this.dataForm.orderSourceId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.orderSourceName = data.tStoreOrderSource.orderSourceName
                this.dataForm.systemBuiltIn = data.tStoreOrderSource.systemBuiltIn.toString()
                this.dataForm.remark = data.tStoreOrderSource.remark
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
				this.disabledSubmit = true
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/store/tstoreordersource/${!this.dataForm.orderSourceId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'orderSourceId': this.dataForm.orderSourceId || undefined,
                'orderSourceName': this.dataForm.orderSourceName,
                'systemBuiltIn': this.dataForm.systemBuiltIn,
                'remark': this.dataForm.remark
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
										this.disabledSubmit = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.disabledSubmit = false
                this.$message.error(data.msg)
              }
            })
          }else {
            this.disabledSubmit = false
          }
        })
      }
    }
  }
</script>
